//
//  DetailViewController.swift
//  SchoolDemo
//
//  Created by rimi on 16/10/8.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController {

    var label1: UILabel?
    var label2: UILabel?
//懒加载网络页面显示范围
lazy var webView: UIWebView = UIWebView(frame: CGRect(x: 0, y: 65, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 65))
    
    override func viewDidLoad() {
        super.viewDidLoad()

       //上方导航栏UI
        setUI()
        //网络请求
        requestWitchGET()
    }

}
//网络请求
extension DetailViewController {

    func requestWitchGET() {
        //获得接口数据
        let urlString = NSURL(string:"http://news.baidu.com")
        //创建网络回话
        let request = NSURLRequest(url: urlString! as URL)
        self.webView.loadRequest(request as URLRequest)
        view.addSubview(webView)
    }
    
}


//上方导航栏UI
extension DetailViewController {
    
    //上方导航栏
    func setUI() {
        view.backgroundColor = UIColor().colorWithHex(0xf0f0f0)
        
        label1 = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
        label1?.backgroundColor = UIColor().colorWithHex(0x009ee7)
        label1?.text = "官方网站"
        label1?.textColor = UIColor.white
        label1?.textAlignment = NSTextAlignment.center
        label1?.font = UIFont.systemFont(ofSize: 20)
        view.addSubview(label1!)
        
        let btn = UIButton()
        btn.frame = CGRect(x: 0, y: 13, width: 44, height: 44)
        btn.setImage(UIImage(named:"返回按钮"), for: UIControlState.normal)
        btn.center.x = self.view.bounds.width / 7
        btn.addTarget(self, action: #selector(clickedBtn), for: UIControlEvents.touchUpInside)
        view.addSubview(btn)
        
    }
    //左上角箭头监听回调
    func clickedBtn() {
        dismiss(animated: true, completion: nil)
    }
}
